<?php
class test_TestMethod extends TestSet {
  function setup() {
    $this->pass = new TestMethod("test_that_passes", "class_name");
    $this->pass->add_assertion(
      new TestAssertion(true, "message")
    );
    $this->pass->output = "output from method";
    $this->pass->line = 242;
    $this->pass_html = $this->pass->toHtml();

    $this->fail = new TestMethod("test_that_fails", "class_name");
    $this->fail->add_assertion(
      new TestAssertion(false, "message")
    );
    $this->fail_html = $this->fail->toHtml();
  }

  function test_should_pass_if_assertions_pass() {
    $this->setup();

    $this->assert($this->pass->passed == true);
  }

  function test_should_fail_if_assertions_fail() {
    $this->assert($this->fail->passed == false);
  }

  function test_should_show_line_number() {
    $this->assert_match($this->pass->line, $this->pass_html);
  }
  
  function test_should_have_ul() {
    $this->assert_match("<ol>", $this->pass_html);
  }

  function test_should_have_method_name() {
    $this->assert_match("test_that_passes:", $this->pass_html);
  }

  function test_should_say_pass_somewhere() {
    $this->assert_match("[^\"]pass", $this->pass_html);
  }

  function test_should_have_passing_list_item() {
    $this->assert_match("<li class=\"Pass\">", $this->pass_html);
  }

  function test_should_have_output() {
    $this->assert_match("output from method", $this->pass_html);
  }

  function test_should_have_assertions_tab_javascript() {
    $regex = "javascript:tab_click\('class_name.test_that_fails.Assertions'\);";
    $this->assert_match($regex, $this->fail_html);
  }

  function test_assertion_tab_should_be_selected() {
    $tab = "<a[^>]*id=\"class_name.test_that_fails.AssertionsTab\"[^>]*class=\"Selected\"";
    $pane = "<div[^>]*id=\"class_name.test_that_fails.Assertions\"[^>]*class=\"TabPane Selected\"";
    
    $this->assert_match($tab, $this->fail_html);
    $this->assert_match($pane, $this->fail_html);
  }

  function test_should_have_elements_with_ids_for_assertions_tab() {
    $pane = "id=\"class_name.test_that_fails.Assertions";
    $tab = $pane . "Tab";
    $this->assert_match($pane, $this->fail_html);
    $this->assert_match($tab, $this->fail_html);
  }

  function test_failing_result_should_print_ok() {
    $this->assert_match("test_that_fails:", $this->fail_html);
    $this->assert_match("[^\"]fail", $this->fail_html);
    $this->assert_match("class=\"Fail\"", $this->fail_html);
  }


  function test_output_should_be_html_entites() {
    $pass = new TestMethod();
    $pass->output = "<br>";
    $this->assert_match("<div[^>]*Output[^>]*>&lt;br&gt;</div>", 
      $pass->toHtml());
  }

  function test_output_should_be_valid_html() {
    $this->assert_valid_html($this->pass_html);
    $this->assert_valid_html($this->fail_html);
  }
}

?>
